import utils from "@/utils/utils.js";
import apis from "@/api/apis.js";//全局API

const useCounter = defineStore('counter', {
  state: () => {
    return {
      receiptType: [  //入库类型
        { name: "采购入库", value: 1 }, { name: "调拨入库", value: 2 }, { name: "销售退货", value: 3 }, { name: "其他入库", value: 4 },
      ],
      entryStatus: [ //入库状态
        { name: "计划中", value: 1 }, { name: "已入库", value: 2 }, { name: "部分入库", value: 3 }, { name: "已取消", value: 4 },
      ],
      inWarehouseStatus: [  //入库单状态
        { name: "待入库", value: 1 }, { name: "已入库", value: 2 }, { name: "部分入库", value: 3 },
      ],
      deliveryType: [
        { name: "调拨", value: "transfer" }, { name: "销售", value: "sale" }, { name: "其他", value: "other" },
      ],
      deliveryStatus: [
        { name: "待出库", value: "wait" }, { name: "全部出库", value: "all" }, { name: "部分出库", value: "partial" }, { name: "已取消", value: "canceled" },
      ],
      transferType: [  //调库类型
        { name: "库存预警", value: 1 }, { name: "满仓调离", value: 2 },
      ],
      outStatus: [  //调库类型-出库状态
        { name: "待出库", value: 0 }, { name: "部分出库", value: 1 }, { name: "全部出库", value: 2 }
      ],
      inStatus: [  //调库类型-入库状态
        { name: "待入库", value: 0 }, { name: "部分入库", value: 1 }, { name: "全部入库", value: 2 }
      ],
      inventoryStatus: [  //盘点状态
        { name: "待盘点", value: "wait" }, { name: "已完成", value: "all" }, { name: "盘点中", value: "partial" }
      ]
    }
  },
  getters: {
    //部门树
    depsTree: (state) => {
      return utils.transformArray([...state.depts], "_id", "parentId")
    }
  },
  actions: {
    idString_format(arrName, e) {
      if (!e) return
      let info = utils.findIndexByField(this[arrName], "value", e)
      return this[arrName][info].name
    },
    //查询货物库存
    async getCargoAmount() {
      let { data } = await apis.queryStoreList()
      return data
    }
  }
})

export default useCounter